import axios from 'axios'

const api = axios.create({
    baseURL: 'http://localhost:8080/api', //基础请求地址
    timeout: 5000                         //请求超时时间(毫秒)
})

// 客户管理API
export const customerApi = {
    addCustomer: (data) => api.post('/customer/add', data),
    getCustomer: (id) => api.get(`/customer/${id}`),
    listCustomers: () => api.get('/customer/list') // 假设有列表接口
}

// 账户管理API
export const accountApi = {
    addAccount: (data) => api.post('/accounts/add', data),
    listAccounts: () => api.get('/accounts/list'),
    deleteAccount: (accountId) => api.post(`/accounts/${accountId}/del`),
    getTransactions: (id) => api.get(`/accounts/${id}/transactions`)
}

// 交易管理API
export const transactionApi = {
    deposit: (data) => api.post('/transactions/deposit', data),
    withdraw: (data) => api.post('/transactions/withdraw', data),
    transfer: (data) => api.post('/transactions/transfer', data),
    getTransaction: (id) => api.get(`/transactions/${id}`)
}

// 响应拦截器
api.interceptors.response.use(response => {
    return response.data
}, error => {
    return Promise.reject(error)
})